﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Mobile.Mvc;
using Microsoft.Practices.Mobile.ContainerModel;

namespace MVCTestClientContainer
{
    public class DetailController : Controller<NorthwindDataSet.ProductsRow>
    {
        [PublishEvent("OnProductLoaded")]
        public event EventHandler ProductLoaded;

        

        public DetailController(IView<NorthwindDataSet.ProductsRow> view)
            : base(view)
        {

        }

        public Container Container
        {
            get;
            set;
        }

        // Selected event from the view
        private void OnBack(object sender, EventArgs e)
        {
            // Move back to the search form
            //NavigationService.GoBack();
            this.Navigator.GoBack();
        }

        protected override void OnInitialize(params object[] parameters)
        {
            this.view.ViewData.Model = parameters[0] 
                            as NorthwindDataSet.ProductsRow;   
            // Notify the view
            if (this.ProductLoaded != null)
            {
                this.ProductLoaded(this, EventArgs.Empty);
            }
        }
    }

}
